// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   check_ok.java

package intrmanufacture.product_providers;

import include.nseer_cookie.counter;
import include.nseer_cookie.exchange;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataTag;

public class check_ok extends HttpServlet
{

	public check_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		HttpSession session = request.getSession();
		nseer_db_backup1 intrmanufacture_db = new nseer_db_backup1(dbApplication);
		nseer_db_backup1 design_db = new nseer_db_backup1(dbApplication);
		ValidataTag vt = new ValidataTag();
		counter count = new counter(dbApplication);
		try
		{
			if (intrmanufacture_db.conn((String)dbSession.getAttribute("unit_db_name")) && design_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String product_providers_recommend_ID = request.getParameter("product_providers_recommend_ID");
				String recommender = request.getParameter("recommender");
				String bodyc = new String(request.getParameter("recommend_describe").getBytes("UTF-8"), "UTF-8");
				String recommend_describe = exchange.toHtml(bodyc);
				String check_time = request.getParameter("check_time");
				String checker = request.getParameter("checker");
				String checker_ID = request.getParameter("checker_ID");
				String product_name = request.getParameter("product_name");
				String product_ID = request.getParameter("product_ID");
				String config_id = request.getParameter("config_id");
				String provider_amount = request.getParameter("provider_amount");
				String sql6 = (new StringBuilder("select id from intrmanufacture_workflow where object_ID='")).append(product_providers_recommend_ID).append("' and ((check_tag='0' and config_id<'").append(config_id).append("') or (check_tag='1' and config_id='").append(config_id).append("'))").toString();
				ResultSet rs6 = intrmanufacture_db.executeQuery(sql6);
				if (!rs6.next())
				{
					if (vt.validata((String)dbSession.getAttribute("unit_db_name"), "intrmanufacture_product_providers_recommend", "product_providers_recommend_ID", product_providers_recommend_ID, "check_tag").equals("0"))
					{
						try
						{
							String sql = (new StringBuilder("update intrmanufacture_product_providers_recommend set check_time='")).append(check_time).append("',checker='").append(checker).append("',recommender='").append(recommender).append("',recommend_describe='").append(recommend_describe).append("',change_tag='0' where product_providers_recommend_ID='").append(product_providers_recommend_ID).append("'").toString();
							intrmanufacture_db.executeUpdate(sql);
							String provider_group = "";
							for (int i = 1; i <= Integer.parseInt(provider_amount); i++)
							{
								String tem_provider_ID = (new StringBuilder("provider_ID")).append(i).toString();
								String provider_ID = request.getParameter(tem_provider_ID);
								String tem_provider_name = (new StringBuilder("provider_name")).append(i).toString();
								String provider_name = request.getParameter(tem_provider_name);
								String sql1 = (new StringBuilder("select * from intrmanufacture_file where provider_ID='")).append(provider_ID).append("'").toString();
								ResultSet rs1 = intrmanufacture_db.executeQuery(sql1);
								if (rs1.next())
								{
									String recommend_products = rs1.getString("recommend_products");
									if (rs1.getString("recommend_products").indexOf(product_name) == -1)
										recommend_products = (new StringBuilder(String.valueOf(recommend_products))).append(product_name).append(", ").toString();
									String sql2 = (new StringBuilder("update intrmanufacture_file set recommend_products='")).append(recommend_products).append("' where provider_ID='").append(provider_ID).append("'").toString();
									intrmanufacture_db.executeUpdate(sql2);
								}
								provider_group = (new StringBuilder(String.valueOf(provider_group))).append(provider_name).append(", ").toString();
							}

							String sql3 = (new StringBuilder("select * from design_file where product_ID='")).append(product_ID).append("'").toString();
							ResultSet rs3 = design_db.executeQuery(sql3);
							if (rs3.next())
							{
								String sql4 = (new StringBuilder("update design_file set provider_group='")).append(provider_group).append("' where product_ID='").append(product_ID).append("'").toString();
								design_db.executeUpdate(sql4);
							}
							String sql9 = (new StringBuilder("update intrmanufacture_workflow set checker='")).append(checker).append("',checker_ID='").append(checker_ID).append("',check_time='").append(check_time).append("',check_tag='1' where object_ID='").append(product_providers_recommend_ID).append("' and config_id='").append(config_id).append("'").toString();
							intrmanufacture_db.executeUpdate(sql9);
							sql9 = (new StringBuilder("select id from intrmanufacture_workflow where object_ID='")).append(product_providers_recommend_ID).append("' and check_tag='0'").toString();
							ResultSet rset = intrmanufacture_db.executeQuery(sql9);
							if (!rset.next())
							{
								sql9 = (new StringBuilder("update intrmanufacture_product_providers_recommend set recommender='")).append(recommender).append("',check_tag='1' where product_providers_recommend_ID='").append(product_providers_recommend_ID).append("'").toString();
								intrmanufacture_db.executeUpdate(sql9);
							} else
							{
								sql9 = (new StringBuilder("update intrmanufacture_product_providers_recommend set recommender='")).append(recommender).append("' where product_providers_recommend_ID='").append(product_providers_recommend_ID).append("'").toString();
								intrmanufacture_db.executeUpdate(sql9);
							}
						}
						catch (Exception ex)
						{
							ex.printStackTrace();
						}
						response.sendRedirect("intrmanufacture/product_providers/check_ok_a.jsp");
					} else
					{
						response.sendRedirect("intrmanufacture/product_providers/check_ok_b.jsp");
					}
				} else
				{
					response.sendRedirect("intrmanufacture/product_providers/check_ok.jsp?finished_tag=2");
				}
				design_db.commit();
				intrmanufacture_db.commit();
				design_db.close();
				intrmanufacture_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
